package com.ww.scala.syntax

/**
 * 流程控制
 */
object syntax01_if_for_while {

  def main(args: Array[String]): Unit = {
    // if
    var a = 2
    if(a>0){
      print(s"a>0  : ${a}")
    }else{
      print(s"a<=0  : ${a}")
    }


    // while
    var b = 3
    while (b<10){
      println(b)
      b+=1
    }

    //for
    println("===========for============")
    var  seqs = 1 to (10,2)
    println(seqs)

    var  seqs1 = 1 until 10
    println(seqs1)

    for(i <- seqs){
      println(i)
    }

    for(i <- seqs1 if(i%2==0)){
      println(i)
    }
    println("------------9*9乘法表------------")
    var k=0
    for(i <- 1 to 9;j <- 1 to 9 if(i>=j)){
        k+=1
        print(s"${i} * $j = ${i*j}  ")
        if(i==j) {
          println()
        }
    }
    println(k)

    val ints = for (i <- 1 to 10) yield {i*2}
    println(ints)
    println("------------yield------------")
    var a1 = 0;
    val numList = List(1,2,3,4,5,6,7,8,9,10);

    // for 循环
    var retVal = for( a1 <- numList if a1 != 3; if a1 < 8 )yield a1

    // 输出返回值
    for( a1 <- retVal){
      println( "Value of a: " + a1 );
    }

  }


}
